package client

import (
	"github.com/Shopify/sarama"
	"log"
)

var (
	KSyncProducer  sarama.SyncProducer
	KAsyncProducer sarama.AsyncProducer
)

func initKafka() {
	dsn := EnvConf.KafkaConf.Dsn

	config := sarama.NewConfig()
	config.Producer.Return.Successes = true
	syncProducer, err := sarama.NewSyncProducer(dsn, config)
	if err != nil {
		log.Fatalf("new kafka syncProducer error %v", err)
	}
	KSyncProducer = syncProducer
	log.Println("kafka sync syncProducer init success")

	asyncProducer, err := sarama.NewAsyncProducer(dsn, config)
	if err != nil {
		log.Fatalf("new kafka asyncProducer error %v", err)
	}
	KAsyncProducer = asyncProducer
}
